﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SwitchWebApp.Models;
using SwitData;

namespace SwitchWebApp.Controllers
{
    public class SwitchTypeController : Controller
    {
        private SwitchWebAppContext db = new SwitchWebAppContext();

        //
        // GET: /SwitchType/

        public ActionResult Index()
        {
            return View(db.SwitchTypes.ToList());
        }

        //
        // GET: /SwitchType/Details/5

        public ActionResult Details(int id = 0)
        {
            PortableSwitchType switchtype = db.SwitchTypes.Find(id);
            if (switchtype == null)
            {
                return HttpNotFound();
            }
            return View(switchtype);
        }

        //
        // GET: /SwitchType/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /SwitchType/Create

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create(PortableSwitchType switchtype)
        {
            if (ModelState.IsValid)
            {
                db.SwitchTypes.Add(switchtype);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(switchtype);
        }

        //
        // GET: /SwitchType/Edit/5

        public ActionResult Edit(int id = 0)
        {
            PortableSwitchType switchtype = db.SwitchTypes.Find(id);
            if (switchtype == null)
            {
                return HttpNotFound();
            }
            return View(switchtype);
        }

        //
        // POST: /SwitchType/Edit/5

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit(SwitchType switchtype)
        {
            if (ModelState.IsValid)
            {
                db.Entry(switchtype).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(switchtype);
        }

        //
        // GET: /SwitchType/Delete/5

        public ActionResult Delete(int id = 0)
        {
            PortableSwitchType switchtype = db.SwitchTypes.Find(id);
            if (switchtype == null)
            {
                return HttpNotFound();
            }
            return View(switchtype);
        }

        //
        // POST: /SwitchType/Delete/5

        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            PortableSwitchType switchtype = db.SwitchTypes.Find(id);
            db.SwitchTypes.Remove(switchtype);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}